Skip to content

Social previews: Show skeleton while rendering messages#48576

Merged
gmjuhasz merged 7 commits intotrunkfrom
fix/social-475-preview-skeleton
May 7, 2026
Merged

Social previews: Show skeleton while rendering messages#48576
gmjuhasz merged 7 commits intotrunkfrom
fix/social-475-preview-skeleton

Conversation

@gmjuhasz
Copy link
Copy Markdown
Contributor

@gmjuhasz gmjuhasz commented May 6, 2026

Fixes SOCIAL-475

Proposed changes

  • Show skeleton placeholders in social preview message text areas while rendered message requests are pending.
  • Keep render-message requests driven by debounced render items so typing only fires one request after debounce.
  • Read rendered message cache without triggering resolver requests from preview consumers.
  • Add regression coverage for debounce/loading states and skeleton rendering.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • Enable the Social message templates feature.
  • Open the post editor and open the Social preview/customization UI.
  • Type a template token such as {excerpt} into the global or per-connection message template.
  • Confirm the preview message area switches to a skeleton immediately, stays skeleton through the debounced render request, then shows the rendered message.
  • Confirm only one /wpcom/v2/publicize/render-messages request fires after typing pauses.
  • Confirm that with the message templates feature disabled, previews continue using the raw message behavior and do not show skeletons.
  • Run pnpm --filter @automattic/social-previews test.
  • Run pnpm --filter @automattic/social-previews typecheck.
  • Run pnpm --filter @automattic/jetpack-publicize test -- use-connection-preview-data use-render-message-items.
  • Run pnpm --filter @automattic/jetpack-publicize typecheck.
CleanShot.2026-05-07.at.11.51.16.mp4

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/social-475-preview-skeleton branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/social-475-preview-skeleton

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 6, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 6, 2026

Code Coverage Summary

Coverage changed in 9 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/publicize/_inc/social-store/actions/rendered-messages.ts 0/3 (0.00%) 0.00% 2 ❤️‍🩹
projects/packages/publicize/_inc/social-store/reducer/rendered-messages.ts 2/5 (40.00%) -26.67% 2 ❤️‍🩹
projects/packages/publicize/_inc/hooks/use-connection-preview-data/index.ts 35/45 (77.78%) 0.28% 1 ❤️‍🩹
projects/packages/publicize/_inc/hooks/use-render-message-items/index.ts 46/58 (79.31%) -0.32% 1 ❤️‍🩹
projects/packages/publicize/_inc/social-store/resolvers.ts 6/33 (18.18%) -0.57% 1 ❤️‍🩹

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

@gmjuhasz gmjuhasz marked this pull request as ready for review May 7, 2026 08:55
@gmjuhasz gmjuhasz added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label May 7, 2026
@gmjuhasz gmjuhasz requested a review from manzoorwanijk May 7, 2026 09:14
@gmjuhasz gmjuhasz self-assigned this May 7, 2026
Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well, but we can improve the code a bit more.

Comment thread projects/packages/publicize/_inc/hooks/use-connection-preview-data/index.ts Outdated
Comment on lines +159 to +163
void registry
.resolveSelect( socialStore )
.getRenderedMessages( postId, items )
// Errors are intentionally swallowed to preserve existing UI behavior.
.catch( () => {} );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to fix any issue we faced while testing?

manzoorwanijk and others added 4 commits May 7, 2026 17:14
…ew-skeleton

# Conflicts:
#	projects/packages/publicize/_inc/hooks/use-connection-preview-data/index.ts
#	projects/packages/publicize/_inc/hooks/use-render-message-items/index.ts
The consumer was stitching loading from three signals — `isResolving`,
`hasFinishedResolution`, and a derived `isWaitingForRenderedMessage` —
to fill the gap between an items-array commit and the resolver actually
finishing. Move that bookkeeping into the slice where it belongs.

Each cache entry is now `{ isLoading: boolean; items?: RenderedMessageBatch }`.
The resolver dispatches `startRenderingMessages` before the apiFetch,
`receiveRenderedMessages` on success, and `finishRenderingMessages` in
the error path (clears `isLoading` without overwriting any prior items,
preserving the "no flash on failure" semantics).

The selector `isLoadingRenderedMessages` returns true when either the
resolver has explicitly marked the slot loading or the entry doesn't
exist yet — the "no entry yet" window covers the gap between debounce
flush and resolver `start`, closing the brief flash where the preview
showed the raw baseMessage.

Consumer collapses to:

  isLoading = templatesEnabled && (isDebouncing || isLoadingRendered)

The debounce check stays in the consumer because the store doesn't see
edits until items are committed — pushing it into the slice would mean
tracking a "latest pending hash" alongside the cache, which is a bigger
change for a small win.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…in items

useRenderMessageItems was checking `hasConnectionMessage` before mode, so
items[i].message kept the old per-network customization even after the
user switched back to global. baseMessage in useConnectionPreviewData is
already mode-gated, so the two sides diverged — `currentRenderItem.message`
never matched `baseMessage` and `isDebouncingRenderedMessage` stayed stuck
true, freezing the preview on the skeleton.

Mirror the consumer's rule exactly: per-connection message + template only
contribute in per-network mode; otherwise globalMessage.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well for me

@gmjuhasz gmjuhasz merged commit 2d22f9c into trunk May 7, 2026
77 checks passed
@gmjuhasz gmjuhasz deleted the fix/social-475-preview-skeleton branch May 7, 2026 12:18
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [Feature] Publicize Now Jetpack Social, auto-sharing [JS Package] Social Previews [Package] Publicize RNA [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants